package io.kiki.sba.registry.common.model.slot.filter;

import com.google.common.base.Objects;
import io.kiki.sba.registry.common.model.PublishSource;
import io.kiki.sba.registry.common.model.constants.MultiValueConstants;
import lombok.NonNull;
import org.springframework.util.CollectionUtils;

import java.util.Set;


public class SyncPublishSourceAcceptor implements SyncSlotAcceptor {

    private static final String NAME = MultiValueConstants.SYNC_PUBLISH_SOURCE_ACCEPTOR;
    private final Set<PublishSource> filters;

    public SyncPublishSourceAcceptor(Set<PublishSource> filters) {
        this.filters = filters;
    }

    @Override
    public boolean accept(SyncAcceptorRequest request) {

        return false;
    }

    @Override
    public boolean filterOut(@NonNull SyncAcceptorRequest request) {

        if (CollectionUtils.isEmpty(filters)) {
            return false;
        }

        return filters.contains(request.getSource());
    }

    @Override
    public String name() {
        return NAME;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        SyncPublishSourceAcceptor that = (SyncPublishSourceAcceptor) o;
        return Objects.equal(NAME, that.NAME);
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(NAME);
    }


}
